<template>
	<view class="padding-bottom-100">
		<form class="flowform">

			<view class="formlist inputtext">
				<view class="formgroup border-bottom-E3E3E5">
					<view class="labletitle">
						<label>贷款金额</label>
					</view>
					<view class="controlvalue">
						<input type="number" name="F_NeedAmount" />
					</view>
					<view>（万元）</view>
				</view>
			</view>
			<view class="formlist inputtext" @tap="F_needDate">
				<view class="formgroup border-bottom-E3E3E5">
					<view class="labletitle">
						<label>期望日期</label>
					</view>
					<view class="controlvalue">
						<input type="text" name="F_needDate" placeholder="选择" disabled="true" />
					</view>
					<view class="advanceicon iconfont icon-xiangyou"></view>
				</view>
			</view>

		</form>
		<view class="formlist">
			<view class="formgroup  padding-17 border-bottom-E3E3E5">
				<view class="labletitletar">
					<label>需求描述</label>
				</view>
				<view class="controlvalue  uni-textarea">
					<textarea name="F_NeedDesc" maxlength="500" :disabled="disabled" placeholder="输入" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import jnpf from '@/common/js/jnpf.js'
	import helper from '@/common/js/helper.js'
	import graceChecker from '@/common/js/graceChecker.js'
	import wPicker from '@/components/w-picker/w-picker.vue'
	let formRule = [

	];
	export default {
		data() {
			return {
				mode: '', //底部弹窗分类
				isSearchShow: false,
				disabled: false, //启用
				status: '', //流程状态
				beflows: {
					operstate: "",
					processId: ''
				},
				travel: {
					billNo: '',
					flowUrgent: '',
					flowTitle: jnpf.userInfo().realName + '的差旅报销申请表',
					applyUser: jnpf.userInfo().realName + "/" + jnpf.userInfo().account,
					applyDate: helper.toDate(new Date, 'yyyy-MM-dd'),
					reimbursementId: '',
					billsNum: '',
					travelerUser: '',
					vehicleMileage: '',
					roadFee: '',
					parkingRate: '',
					businessMission: '',
					breakdownFee: '',
					setOutDate: '',
					returnDate: '',
					destination: '',
					planeTicket: '',
					fare: '',
					getAccommodation: '',
					railTransit: '',
					travelAllowance: '',
					mealAllowance: '',
					other: '',
					total: '',
					reimbursementAmount: '',
					loanAmount: '',
					sumOfMoney: ''
				},
				isBtnClicks: false,
				pickerList: [],
				urgentList: [{
						label: "普通",
						value: "1"
					},
					{
						label: "重要",
						value: "2"
					},
					{
						label: "紧急",
						value: "3"
					}
				],
				statusType: ''
			}
		},
		onLoad(e) {
			/* 工作区进入状态 */
			let statusType = uni.getStorageSync("type")
			this.statusType = statusType
			/* 工作区进入状态 End*/
			let flowInfo = JSON.parse(e.flowInfo);
			this.beflows.operstate = flowInfo.operstate;
			if (flowInfo.operstate == 'add') {
				this.travel.flowId = flowInfo.id;
				this.status = 0;
				this.travel.flowUrgent = helper.getSpinnerNew(this.urgentList, '1');
				helper.ajax({
					url: '/api/System/BillRule/BillNumber/WF_TravelReimbursementNo',
					success: res => {
						this.travel.billNo = res.data.data;
					}
				});
			}
			if (flowInfo.operstate == 'info') {
				this.disabled = flowInfo.disabled;
				this.beflows.processId = flowInfo.id;
				this.status = flowInfo.status;
				helper.ajax({
					url: '/api/WorkFlowForm/TravelReimbursement/' + flowInfo.id,
					success: res => {
						let _travel = res.data.data;
						this.travel = _travel;
						this.travel.flowUrgent = helper.getSpinnerNew(this.urgentList, _travel.flowUrgent);
						this.travel.applyDate = helper.toDate(_travel.applyDate, 'yyyy-MM-dd');
						this.travel.returnDate = helper.toDate(_travel.returnDate, "yyyy-MM-dd HH:mm");
						this.travel.setOutDate = helper.toDate(_travel.setOutDate, "yyyy-MM-dd HH:mm");
					}
				});
			}
		},
		methods: {
			flowUrgent(e) {
				if (!this.disabled) {
					this.pickerList = this.urgentList;
					this.mode = "selector";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.travel.flowUrgent = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			setOutDate(e) {
				if (!this.disabled) {
					this.mode = "dateTime";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.travel.setOutDate = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			returnDate(e) {
				if (!this.disabled) {
					this.mode = "dateTime";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.travel.returnDate = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			submit(e) {
				let formData = this.travel;
				if (!graceChecker.check(formData, formRule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.isBtnClicks = true;
				formData.flowUrgent = helper.setSpinnerNew(this.urgentList, formData.flowUrgent);
				formData.status = 0;
				let method = "POST";
				let url = "/api/WorkFlowForm/TravelReimbursement";
				if (formData.id) {
					method = "PUT";
					url = url + "/" + formData.id
				}
				formData.applyDate = Date.parse(formData.applyDate);
				formData.returnDate = Date.parse(formData.returnDate);
				formData.setOutDate = Date.parse(formData.setOutDate);
				helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					data: formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate == 'add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						} else {
							uni.navigateBack();
						}
						this.isBtnClicks = false
					}
				});
			},
			save(e) {
				let formData = this.travel;
				if (!graceChecker.check(formData, formRule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.isBtnClicks = true;
				formData.flowUrgent = helper.setSpinnerNew(this.urgentList, formData.flowUrgent);
				formData.status = 1;
				let method = "POST";
				let url = "/api/WorkFlowForm/TravelReimbursement";
				if (formData.id) {
					method = "PUT";
					url = url + "/" + formData.id
				}
				formData.applyDate = Date.parse(formData.applyDate);
				formData.returnDate = Date.parse(formData.returnDate);
				formData.setOutDate = Date.parse(formData.setOutDate);
				helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					data: formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate == 'add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						} else {
							uni.navigateBack();
						}
						this.isBtnClicks = false
					}
				});
			},
		},
		components: {
			wPicker
		}
	}
</script>


<style>
	.controlvalue {
		width: 50%;
	}
</style>